package com.dqhl.community.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.dqhl.community.R;

/**
 * Created by Administrator on 2016/9/5.
 */

public class LuocangDialog extends Dialog implements View.OnClickListener{
    private Context context;
    private String content_one; // dialog 提示的内容1
    private String content_two; // dialog 提示的内容2
    private String confirm; // dialog 确定按钮显示内容

    private ButtonClickListener buttonClickListener;

    public void setButtonClickListener(ButtonClickListener buttonClickListener) {
        this.buttonClickListener = buttonClickListener;
    }

    public LuocangDialog(Context context, String content_one,String content_two, String confirm) {
        super(context, R.style.CustomDialog);
        this.context = context;
        this.content_one = content_one;
        this.content_two = content_two;
        this.confirm = confirm;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initView();
    }

    private void initView() {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.luocangdialog_confirm, null);
        setContentView(view);

        TextView tv_contentOne = (TextView) view.findViewById(R.id.tv_content);
        TextView tv_contentTwo = (TextView) view.findViewById(R.id.tv_nextContent);
        Button btnConfirm = (Button) view.findViewById(R.id.btn_confirm);
//        Button btnCancel = (Button) view.findViewById(R.id.btn_cancel);

        tv_contentOne.setText(content_one);
        tv_contentTwo.setText(content_two);
        btnConfirm.setText(confirm);

        btnConfirm.setOnClickListener(this);

        Window window = getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        DisplayMetrics dm = context.getResources().getDisplayMetrics();
        lp.width = (int) (dm.widthPixels * 0.8);
        window.setAttributes(lp);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_confirm:
                buttonClickListener.doConfirm();
                break;
//            case R.id.btn_cancel:
//                buttonClickListener.doCancel();
//                break;
        }
    }

    public interface ButtonClickListener {

        void doConfirm();

//        void doCancel();
    }
}